package com.ldzg.blockwatcher.risk;

import com.ldzg.blockwatcher.notify.factory.NotifyFactory;
import com.ldzg.blockwatcher.notify.enums.NotifyType;
import com.ldzg.blockwatcher.risk.dto.TransactionInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 18310740596@163.com
 * @version V1.0.0
 * @since 2025-07-05 11:16:03
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RiskEngine {

    private final List<IRiskRule> riskRules;
    private final NotifyFactory notifyFactory;

    public void check(TransactionInfo transactionInfo) {
        int totalScore = riskRules.stream()
                         .mapToInt(rule -> rule.getScore(transactionInfo))
                         .sum();

        if (totalScore >= 80) {
            log.warn("交易[{}]触发风控,风险总分:{}", transactionInfo.getTxHash(), totalScore);

            notifyFactory.getStrategy()
                         .warningAddress(transactionInfo.getSource(), transactionInfo.getToAddress());
        }
    }
}